package simple;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 获取栈中最小的元素
 */
public class MinStack {
    private Deque<Integer> xStack ;
    private Deque<Integer> minStack;

    /** initialize your data structure here. */
    public MinStack() {
      this.xStack = new LinkedList<>();
      this.minStack = new LinkedList<>();
      minStack.push(Integer.MAX_VALUE);
    }

    public void push(int x) {
       xStack.push(x);
       minStack.push(Math.min(minStack.peek(),x));
    }

    public void pop() {
      xStack.pop();
      minStack.pop();
    }

    public int top() {
      return  xStack.peek();
    }

    public int min() {
      return  minStack.peek();
    }
}
